<?php
/**
 * Created by PhpStorm.
 * User: Sky
 * Date: 2017/8/3
 * Time: 下午3:12
 */

use yii\helpers\Url;

$web = Url::base();
$this->title = '系统消息';
?>


<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline">
            <div class="btn-group col-lg-1">
                <a class="btn btn-default " type="button" data-toggle="modal" href="#addModal" data-id='0'>
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>

            <div class="pull-right">
                <input type="text" class="form-control" id="title" placeholder="标题名称" value="<?= $title ?>">

                <button type="button" class="btn btn-primary" onclick="filter()"><i class="fa fa-search"></i> 搜索
                </button>
            </div>
        </div>
    </div>
</div>


<!-- body table-->
<div class="panel panel-default" id="card_sale_list">
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <thead class="nowrap">
                <tr>
                    <th>标题</th>
                    <th>内容</th>
                    <th>创建日期</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <?php
                if ($items != null && count($items) > 0) {
                    for ($i = 0; $i < count($items); $i++) {
                        ?>
                        <tr>
                            <td>
                                <?= $items[$i]['title'] ?>
                            </td>
                            <td>
                                <?= $items[$i]['content'] ?>
                            </td>
                            <td>
                                <?= \app\librarys\Tools::dateFormat($items[$i]['create_datetime']) ?>
                            </td>
                            <td>
                                <div class="btn-group">
                                    <a class="btn btn-link" data-toggle="modal" data-id="<?= $items[$i]['id'] ?>"
                                       href="#addModal">编辑</a>
                                </div>
                            </td>
                        </tr>
                        <?php
                    }
                }
                ?>
                </tbody>
            </table>
        </div>
        <div class="pull-left">
            <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
        </div>
    </div>
</div>

<!--add dialog-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="addModal" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">系统消息</h4>
            </div>
            <div class="modal-body" id="detail_content">
                正在加载数据....
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button class="btn btn-primary" id="btnAddOk">确定</button>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
    (function () {
        $('#addModal').on('show.bs.modal', function (e) {
            $("#detail_content").html('正在加载数据....');
            var id = e.relatedTarget.attributes['data-id'].value;
            requestHtml('system-message-detail-partial', {id: id}, true, function (responseHtml) {
                $("#addModal").find("#detail_content").html(responseHtml);
            });
        });

        $('#btnAddOk').click(function () {
            var data = {};
            data.id = $('#hiddenId').val();
            data.title = $('#inputTitle').val().trim();
            data.content = $('#inputContent').val().trim();
            requestJson('system-message-save-handler', data, true, function (responseData) {
                if (responseData.status == 0) {
                    window.location.reload();
                }
            })
        });
    })(jQuery);

    //设置模态窗:当用户点击模态框外部时不会关闭、当初始化时不显示模态框。
    $(function () {
        $('#addModal').modal({
            backdrop: 'static', show: false
        });
    });


</script>